const JSZip = require("jszip");
const fs = require('fs')
const data = fs.readFileSync('./output/合同帐户5.3.docx')
const {toJson} = require('./utils/index')

async function logContent (data) {
  const map = new Map()
  const zipContent = await JSZip.loadAsync(data)
    for (const [key, value] of Object.entries(zipContent.files)) {
      console.log('key', key)
      const json = toJson(await value.async('text'))
      console.log('json', json) // 这里可以输出json内容
      map.set(key, json)
  }
  return map
}

async function getDocument (data) {
  const zipContent = await JSZip.loadAsync(data)
      for (const [key, value] of Object.entries(zipContent.files)) {
        if (key.endsWith('document.xml')) {
          return toJson(await value.async('text'))
        }
      }
}

// logContent(data).then(res => {
//   fs.writeFileSync(
//     './output/map.txt',
//     JSON.stringify(Array.from(res))
//   )
// })


getDocument(data).then(json => {
    fs.writeFileSync('./output/map.json', JSON.stringify(json))
})